<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Generate key</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.rnp-op-encrypt.html">« rnp_op_encrypt</a></li>
      <li style="float: right;"><a href="function.rnp-op-sign-cleartext.html">rnp_op_sign_cleartext »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.rnp.html">Rnp 函数</a></li>
    <li>Generate key</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.rnp-op-generate-key" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">rnp_op_generate_key</h1>
  <p class="verinfo">(PECL rnp &gt;= 0.1.1)</p><p class="refpurpose"><span class="refname">rnp_op_generate_key</span> &mdash; <span class="dc-title">Generate key</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.rnp-op-generate-key-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>rnp_op_generate_key</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.rnpffi.html" class="type RnpFFI">RnpFFI</a></span> <code class="parameter">$ffi</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$userid</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$key_alg</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$sub_alg</code><span class="initializer"> = ?</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code><span class="initializer"> = ?</span></span><br>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">

  </p>


 </div>


 <div class="refsect1 parameters" id="refsect1-function.rnp-op-generate-key-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">ffi</code></dt>

    <dd>

     <p class="para">
      The FFI object returned by rnp_ffi_create.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">userid</code></dt>

    <dd>

     <p class="para">
      PGP User ID - text that is intended to represent
      the name and email address of the key holder.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">key_alg</code></dt>

    <dd>

     <p class="para">
      Primary key algorithm (i.e. &#039;RSA&#039;, &#039;DSA&#039;, etc).
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">sub_alg</code></dt>

    <dd>

     <p class="para">
      Subkey algorithm. If not set, subkey will not be generated.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">options</code></dt>

    <dd>

     <p class="para">
      An associative array with options.
     </p>
     <table class="doctable informaltable">
      
       <thead>
        <tr>
         <th>Key</th>
         <th>Data type</th>
         <th>说明</th>
        </tr>

       </thead>

       <tbody class="tbody">
        <tr>
         <td><code class="literal">&quot;bits&quot;</code></td>
         <td>integer</td>
         <td>Primary key size in bits. Applicable only to RSA, DSA and El-Gamal keys.</td>
        </tr>

        <tr>
         <td><code class="literal">&quot;hash&quot;</code></td>
         <td>string</td>
         <td>Hash algorithm used in self signature or subkey binding signature.</td>
        </tr>

        <tr>
         <td><code class="literal">&quot;dsa_qbits&quot;</code></td>
         <td>integer</td>
         <td>Set size of a <code class="literal">q</code> parameter for DSA key.
          Note: appropriate default value will be set, depending on key bits. However you may
          override it if needed.</td>
        </tr>

        <tr>
         <td><code class="literal">&quot;curve&quot;</code></td>
         <td>string</td>
         <td>Set the curve used for ECC key. Note: this is only applicable for ECDSA, ECDH and SM2 keys.</td>
        </tr>

        <tr>
         <td><code class="literal">&quot;request_password&quot;</code></td>
         <td>boolean</td>
         <td>Enable requesting password via password provider. This password
          will be used for key encryption. Password provider callback function should be set in
	  advance by calling <span class="function"><a href="function.rnp-ffi-set-pass-provider.html" class="function">rnp_ffi_set_pass_provider()</a></span>.
          Note: this setting will be ignored if password was set via<code class="literal">&quot;password&quot;</code></td>
        </tr>

        <tr>
         <td><code class="literal">&quot;password&quot;</code></td>
         <td>string</td>
         <td>Set the password used to encrypt the secret key data.</td>
        </tr>

        <tr>
         <td><code class="literal">&quot;expiration&quot;</code></td>
         <td>integer</td>
         <td>Set the key and subkey expiration time in seconds.</td>
        </tr>

        <tr>
         <td><code class="literal">&quot;sub_bits&quot;</code></td>
         <td>integer</td>
         <td>Subkey size in bits. Applicable only to RSA, DSA and El-Gamal keys.</td>
        </tr>

        <tr>
         <td><code class="literal">&quot;sub_hash&quot;</code></td>
         <td>string</td>
         <td>Hash algorithm used in subkey self signature or subkey binding signature.</td>
        </tr>

        <tr>
         <td><code class="literal">&quot;sub_curve&quot;</code></td>
         <td>string</td>
         <td>Set the curve used for ECC subkey. Note: this is only applicable for ECDSA, ECDH and SM2 keys.</td>
        </tr>

       </tbody>
      
     </table>

    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.rnp-op-generate-key-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Fingerprint of the generated primary key 或者在失败时返回 <strong><code>false</code></strong>. This fingerprint can be used
   later to reference the key in sign and encrypt operations. The key data is stored in FFI
   memory context and can be saved using
   <span class="function"><a href="function.rnp-save-keys.html" class="function">rnp_save_keys()</a></span> or <span class="function"><a href="function.rnp-save-keys-to-path.html" class="function">rnp_save_keys_to_path()</a></span>.
  </p>
 </div>



</div></div></div></body></html>